package gat.common.util;

import cn.hutool.core.util.StrUtil;
import org.apache.commons.lang3.StringUtils;

public class DesensitizedUtils {

    private DesensitizedUtils(){}

    public static String mobilePhone(String num) {
        return StrUtil.isBlank(num) ? "" : StrUtil.hide(num, 3, num.length() - 4);
    }

    public static String idCardNum(String idCardNum, int front, int end) {
        if (StrUtil.isBlank(idCardNum)) {
            return "";
        } else if (front + end > idCardNum.length()) {
            return "";
        } else {
            return front >= 0 && end >= 0 ? StrUtil.hide(idCardNum, front, idCardNum.length() - end) : "";
        }
    }

    public static String chineseOrigName(String name){

        if (StringUtils.isBlank(name)){
            return "";
        }

        if (name.length() < 3){
            return chineseName(name);
        }

        String lastName = StringUtils.left(name, 1);
        String firstName = StringUtils.right(name, 1);
        StringBuilder medi = new StringBuilder();
        for (int i = 0; i < name.length() - 2; i++) {
            medi.append("*");
        }

        return lastName + medi + firstName;
    }

    public static String chineseName(String fullName) {
        return StrUtil.isBlank(fullName) ? "" : StrUtil.hide(fullName, 1, fullName.length());
    }

}
